package tarantula.collector;


public class ExecResults {
	int failing_test_num = 0;
	int passing_test_num = 0;
	
	public final int total_failing_test_num;
	public final int total_passing_test_num;
	
	public ExecResults(int total_failing, int total_passing) {
		assert total_failing > 0;
		assert total_passing > 0;
		
		this.total_failing_test_num = total_failing;
		this.total_passing_test_num = total_passing;
	}
	
	public void incrFailingTestNum() {
		this.failing_test_num++;
	}
	public void incrPassingTestNum() {
		this.passing_test_num++;
	}
	
	public float computeSuspiciousness() {
		float fail = ((float)failing_test_num) / ((float)total_failing_test_num);
		float pass = ((float)passing_test_num) / ((float)total_passing_test_num);
		
		return fail / (fail + pass);
	}
	
	public float computeConfidence() {
		float fail = ((float)failing_test_num) / ((float)total_failing_test_num);
		float pass = ((float)passing_test_num) / ((float)total_passing_test_num);
		
		return Math.max(fail, pass);
	}
	
	
	@Override
	public int hashCode() {
		return this.failing_test_num*29 + this.passing_test_num*59 + 
		    71*total_failing_test_num + 97*total_passing_test_num;
	}
	
	@Override
	public boolean equals(Object obj) {
		if(!(obj instanceof ExecResults)) {
			return false;
		}
		ExecResults er = (ExecResults)obj;
		return this.failing_test_num == er.failing_test_num
		    && this.passing_test_num == er.passing_test_num
		    && this.total_failing_test_num == er.total_failing_test_num
		    && this.total_passing_test_num == er.total_passing_test_num;
	}
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		
		sb.append("fail num: " + this.failing_test_num + ",  pass num: " + this.passing_test_num);
		sb.append(", total fail: " + this.total_failing_test_num + ",  total pass: " + this.total_passing_test_num);
		sb.append(", suspicious: " + this.computeSuspiciousness());
		sb.append(", confidence: " + this.computeConfidence());
		
		return sb.toString();
	}
}
